<template>
  <div  class="wrapper">
    <BreakSpace label="基本信息" :containerStyle="{ marginBottom: '15px' }" />
    <div style="height:200px">
      <FormPanel
        ref="from"
        :list="initForm"
        :cols="3"
        :formType="value.type"
        :labelWidth="120"
        :isSubmitBtn="false"
        :collapse="false"
        @formChange="changeHandle"
      />
    </div>
    <BreakSpace label="配件信息" :containerStyle="{ marginBottom: '15px' }" />
    <FilterTable
      height="auto"
      ref="dealerRoleTable"
      :columns="partColumns"
      :dataSource="partList"
      :isSelectColumn="isSelectColumn"
      :datakey="'records'"
      :isToperInfo="false"
      :onColumnsChange="partColumns => (this.partColumns = partColumns)"
      columnsRef="notification_maintain_info_02"
    >
    </FilterTable>
    <BreakSpace label="审核信息" :containerStyle="{ marginBottom: '15px' }" />
    <!-- <FilterTable
      height="300"
      ref="dealerRoleTable"
      :columns="approveColumns"
      :dataSource="approveRecordList"
      :isSelectColumn="isSelectColumn"
      :datakey="'records'"
      :isToperInfo="false"
      :onColumnsChange="approveColumns => (this.approveColumns = approveColumns)"
      columnsRef="notification_maintain_info_02"
    >
    </FilterTable> -->
    <approveHistory v-model="approvalparams" />
    <div v-show="ckclFlag">
      <FormPanel
        ref="from"
        :list="initForm1"
        :cols="3"
        :formType="value.type"
        :labelWidth="120"
        :isSubmitBtn="false"
        :collapse="false"
        @formChange="changeHandle"
      />
    </div>

    <div class="dialogBottmView">
      <el-button @click="closeDialog('closeDialog')">返 回</el-button>
    </div>
  </div>
</template>

<script>
import { getFileGroup } from '@/api/partsmanage/common/file';
import { getPartsGroup } from '@/api/partsmanage/claim/apply';
import {getAllUser} from '@/api/customerRepair/activityVisit/resultEntry/index';
import { dictionary } from '@/utils/dictMixin';
import approveHistory from '../../components/approveHistory';
// import { getApproveRecord } from '@/api/partsmanage/claim/approverecord';
import moment from 'moment';
export default {
  name: 'chaimqueryinfo',
  mixins: [dictionary],
  props:{
    value: {
      type: Object,
      data: Object,
      required: true
    },
  },
  components:{
    approveHistory
  },
  data() {
    this.saveData=null;
    return {
      type: this.value.type,
      initForm : this.initFormFun(),
      initForm1: this.initFormFun1(),
      partColumns: this.creatHeaderPartRoleColumns(),
      approveColumns: this.creatHeaderApproveColumns(),
      partList: [],
      approveRecordList: [],
      isSelectColumn: false,
      formData:{},
      approvalparams: {},
      ckclFlag: false,
    };
  },
  created() {
    this.initColunm()
    this.init(this.value.data)
  },
  methods: {
    init(data) {
      if(this.type==='show'){
        var spid = data.id
        getPartsGroup({ "spid": spid }).then(response => {
          this.partList = response.data.records
        })
        this.approvalparams.xtspid = spid
        this.approvalparams.xtsplx = 'tt_part_claim'
        this.initForm.forEach(x => {
          if (x.fieldName === 'created_at') {
            x.initialValue = moment(data[x.fieldName]).format('YYYY-MM-DD HH:mm:ss');
          } else {
            x.initialValue = data[x.fieldName];
          }
        });
        getFileGroup({ "xtdjid": spid, "xtfjlx": "1" }).then(response => {
          var fileList = response.data.records
          this.initForm.forEach(x => {
            if (x.fieldName === 'wayFiles') {
              x.initialValue = fileList
            }
          })
        })
        if (data.xsddzt === 50071006) {
          this.ckclFlag = true
          getFileGroup({ "xtdjid": spid, "xtfjlx": "2" }).then(response => {
            var fileList = response.data.records
            this.initForm1.forEach(x => {
              if (x.fieldName === 'ckFiles') {
                x.initialValue = fileList
              } else {
                x.initialValue = data[x.fieldName];
              }
            })
          })
        }
      }
    },
    async initColunm() {
      let res= await getAllUser();
      this.approveColumns.find(x => x.dataIndex == 'created_by').dictItems = res.data.map(x => ({text: x.employeeName, value: x.userId}));
    },
    //取消操作
    closeDialog(type) {
      this.$emit('close', {visible: false, type: type});
    },
    initFormFun(){
      return [
        {
          type: 'INPUT',
          label: '索赔单号',
          fieldName: 'spddhm',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
          rules: [{
            required: true,
            message: '必填',
            trigger: 'blur'
          }]
        },
        {
          type: 'SELECT',
          label: '索赔类型',
          fieldName: 'bssplx',
          placeholder: '请选择',
          initialValue: "",
          disabled: true,
          itemList: this.createDictList('5006'),
          rules: [{
            required: true,
            message: '必填',
            trigger: 'change'
          }]
        },
        {
          type: 'INPUT',
          label: '创建日期',
          fieldName: 'created_at',
          placeholder: '请输入',
          initialValue:  moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经办人',
          fieldName: 'xtczry',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
          rules: [{
            required: true,
            message: '必填',
            trigger: 'blur'
          }]
        },
        {
          type: 'INPUT',
          label: '经办人电话',
          fieldName: 'sprydh',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
          rules: [{
            required: true,
            message: '必填',
            trigger: 'blur'
          }]
        },
        {
          type: 'INPUT',
          label: '采购单号',
          fieldName: 'cgddhm',
          placeholder: '请输入',
          initialValue: '',
          readonly:true,
          disabled: true,
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun(1)}></el-button>
              </div>
            );
          },
          rules: [{
            required: true,
            message: '必填',
            trigger: 'blur'
          }]
        },
        // {
        //   type: 'UPLOAD_FILE',
        //   label: '附件上传',
        //   fieldName: 'fjsc',
        //   placeholder: '请输入',
        //   disabled: true,
        //   initialValue:[],
        //   offsetRightCols:2
        // },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'bsspbz',
          placeholder: '请输入',
          disabled: true,
          selfCols:3
        },
        {
          selfCols: 3,
          type: 'UPLOAD_FILE',
          label: '上传文件',
          fieldName: 'wayFiles',
          placeholder: '上传文件...',
          disabled: true,
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 2,
            tipText: '（支持：PDF、RAR、JPG格式）'
          }
        }
      ]
    },
    changeHandle(val){
      this.saveData=val
    },
    creatHeaderPartRoleColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        { title: '采购单号', dataIndex: 'cgddhm', sorter: true },
        { title: '配件代码', dataIndex: 'bjxmbh', sorter: true },
        { title: '配件名称', dataIndex: 'bjzwmc', sorter: true },
        { title: '仓库', dataIndex: 'bsckmc', sorter: true },
        { title: '采购数量', dataIndex: 'bstxsl', sorter: true },
        {
          title: '索赔数量',
          dataIndex: 'bsspsl',
          sorter: true,
         },
        { title: '采购单价', dataIndex: 'xsxsdj', sorter: true },
        { title: '折扣率', dataIndex: 'pjzkl', sorter: true },
        { title: '加收管理费率', dataIndex: 'jsglfl', sorter: true },
        // { title: '加价率', dataIndex: 'text9', sorter: true },
        { title: '加价后单价', dataIndex: 'jjhdj', sorter: true },
        { title: '采购金额', dataIndex: 'xsysje', sorter: true },
        { title: '索赔金额', dataIndex: 'bsspje', sorter: true },
        { title: '配件属性', dataIndex: 'bjpjsx', sorter: true, render: props => { return <span>{this.createDictText(props.row.bjpjsx, '5000')}</span>; } }
      ];
    },
    creatHeaderApproveColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        { title: '审核日期', dataIndex: 'created_at', sorter: true, dateFormat: 'yyyy-MM-dd HH:mm:ss', },
        { title: '审核人', dataIndex: 'created_by', sorter: true },
        { title: '审核状态', dataIndex: 'xtspzt', sorter: true },
        { title: '审核意见', dataIndex: 'xtspnr', sorter: true }
      ];
    },
    initFormFun1() {
      return [
        {
          type: 'TEXT_AREA',
          label: '仓库处理结果',
          fieldName: 'bsckcl',
          placeholder: '请输入',
          disabled: true,
          selfCols:3
        },
        {
          selfCols: 3,
          type: 'UPLOAD_FILE',
          label: '上传文件',
          fieldName: 'ckFiles',
          placeholder: '上传文件...',
          disabled: true,
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 2,
            tipText: '（支持：PDF、RAR、JPG格式）'
          }
        }
      ]
    }
  }
};
</script>
<style scoped>
.wrapper {
  height: calc(100vh - 110px);
}
</style>
